dojo.provide("msos.selection");
var sel_dump=null;
if(djConfig.msos_debug){
dojo.require("msos.dumper");
sel_dump=msos.dumper.dump;
}
msos.selection.generate_object=function(_1,_2,_3){
var _4=this;
this.debug=false;
this.get_selection=function(){
if(window.getSelection){
return _1.getSelection();
}else{
if(document.selection){
return _1.document.selection;
}else{
return null;
}
}
};
this.get_range=function(_5){
if(!_5){
return null;
}
if(window.getSelection){
return _5.getRangeAt(0);
}else{
if(document.selection){
return _5.createRange();
}else{
return null;
}
}
};
this.create_range=function(){
if(window.getSelection){
return _2.createRange();
}else{
if(document.selection){
return _2.body.createControlRange();
}else{
return null;
}
}
};
this.set_focus=function(){
if(dojo.isOpera){
_3.blur();
_3.focus();
}else{
_1.focus();
}
};
this.selection_str_end=function(){
var _6={start:0,end:0,offset:0,offset_tar:0,pos_debug:{},string:"",range:null,select:null,target:null,max:0};
var _7=0;
var _8=0;
var _9=null;
var _a=null;
var _b=_4.get_selection();
var _c=_4.get_range(_b);
if(window.getSelection){
var _d=0;
var _e=null;
_9=_b.anchorNode||null;
_a=_9.parentNode||null;
_7=_b.anchorOffset;
_8=_b.focusOffset;
_6.string=_b.toString()||"no text selected";
if(_a&&_a.hasChildNodes()){
_e=_a.firstChild;
}
while(_e&&(_e!==_9)){
if(_e.nodeType==3){
_d+=_e.nodeValue.length;
}
_e=_e.nextSibling;
}
_6.offset=_d;
_d=0;
if(_a){
_e=_a.parentNode.firstChild;
}else{
_e=null;
}
while(_e&&(_e!==_a)){
if(_e.nodeType==3){
_d+=_e.nodeValue.length;
}
_e=_e.nextSibling;
}
_6.offset_tar=_d;
}else{
if(document.selection){
var _f=0;
var _10=0;
var _11=_c.duplicate();
_a=_c.parentElement();
if(_11){
while(_11.moveStart("character",-1)!=0){
_7++;
}
while(_11.moveEnd("character",-1)!=0){
_8++;
}
}
var _12=_1.document.body.createTextRange();
_12.moveToElementText(_a);
if(_12){
while(_12.moveStart("character",-1)!=0){
_f++;
}
}
_7=_7-_f;
_8=_8-_f;
_6.string=_c.text||"no text selected";
}
}
_6.range=_c;
_6.select=_b;
_6.start=_7;
_6.end=_8;
_6.target=_a;
_6.max=msos.selection.get_node_txt_length(_a);
_6.pos_debug={str:_6.start,end:_6.end,max:_6.max,offset:_6.offset,tar_off:_6.offset_tar,string:_6.string};
if(_9){
_6.pos_debug.child_name=_9.nodeName;
_6.pos_debug.child_id=(_9.id||"na");
}
if(_a){
_6.pos_debug.target_name=_a.nodeName;
_6.pos_debug.target_id=(_a.id||"na");
}
_6.start=_6.start>0?_6.start:0;
_6.end=_6.end>0?_6.end:0;
_6.end=(_6.end<_6.start)?_6.start:_6.end;
_6.pos_debug.str_rev=_6.start;
_6.pos_debug.end_rev=_6.end;
if(sel_dump&&_4.debug){
sel_dump.setObjectName("Cursor Start/End Hash");
sel_dump.popup(_6.pos_debug);
}
return _6;
};
this.set_start_end=function(_13,_14,end){
var _16=true;
var _17=0;
var _18=null;
if(window.getSelection){
var _19=null;
_13.innerHTML=_13.innerHTML;
_18=_4.create_range();
if(_13&&_13.hasChildNodes()){
_19=_13.firstChild;
}
while(_19){
if(_19.nodeType==3){
if(_16){
if(_14<=(_19.nodeValue.length+_17)){
_18.setStart(_19,_14-_17);
_16=false;
}
}
if(!_16){
if(end<=(_19.nodeValue.length+_17)){
_18.setEnd(_19,end-_17);
break;
}
}
_17+=_19.nodeValue.length;
}
_19=_19.nextSibling;
}
}else{
if(document.selection){
_4.selectElementChildren(_13);
var sel=_4.get_selection();
_18=_4.get_range(sel);
_18.moveStart("character",_14);
_18.collapse("true");
if(_14!=end){
_18.moveEnd("character",(end-_14));
}
}
}
return _18;
};
this.getType=function(){
if(window.getSelection){
var _1b="text";
var _1c,_1d;
try{
_1c=_4.get_selection();
_1d=_4.get_range(_1c);
}
catch(e){
console.error("generate_object - getType -> failed: "+e);
}
if(_1c&&_1c.rangeCount==1){
if((_1d.startContainer==_1d.endContainer)&&((_1d.endOffset-_1d.startOffset)==1)&&(_1d.startContainer.nodeType!=3)){
_1b="control";
}
}
return _1b;
}else{
if(document.selection){
return _2.selection.type.toLowerCase();
}else{
return null;
}
}
};
this.getSelectedText=function(){
if(window.getSelection){
var _1e=_4.get_selection();
if(_1e){
return _1e.toString();
}
}else{
if(document.selection){
if(_4.getType()=="control"){
return null;
}
var _1f=_4.get_selection();
var _20=_4.get_range(_1f);
return _20.text;
}
}
return null;
};
this.getSelectedHtml=function(){
if(window.getSelection){
var _21=_4.get_selection();
var _22=_4.get_range(_21);
if(_21&&_21.rangeCount){
var _23=_22.cloneContents();
var div=_2.createElement("div");
div.appendChild(_23);
return div.innerHTML;
}
return null;
}else{
if(document.selection){
if(_4.getType()=="control"){
return null;
}
var _25=_4.get_selection();
var _26=_4.get_range(_25);
return _26.htmlText;
}else{
return null;
}
}
};
this.getSelectedElement=function(){
if(_4.getType()=="control"){
if(window.getSelection){
var _27=_4.get_selection();
return _27.anchorNode.childNodes[_27.anchorOffset];
}else{
if(document.selection){
var _28=_4.get_selection();
var _29=_4.get_range(_28);
if(_29&&_29.item){
return _2.selection.createRange().item(0);
}
}
}
}
return null;
};
this.getParentElement=function(){
if(_4.getType()=="control"){
var p=_4.getSelectedElement();
if(p){
return p.parentNode;
}
}else{
if(window.getSelection){
var _2b=_4.get_selection();
if(_2b){
var _2c=_2b.anchorNode;
while(_2c&&(_2c.nodeType!=1)){
_2c=_2c.parentNode;
}
return _2c;
}
}else{
if(document.selection){
var _2d=_4.get_selection();
var _2e=_4.get_range(_2d);
return _2e.parentElement();
}
}
}
return null;
};
this.hasAncestorElement=function(_2f){
return _4.getAncestorElement.apply(arguments)!=null;
};
this.getAncestorElement=function(_30){
var _31=_4.getSelectedElement()||_4.getParentElement();
return _4.getParentOfType(_31,arguments);
};
this.isTag=function(_32,_33){
if(_32&&_32.tagName){
var _34=_32.tagName.toLowerCase();
for(var i=0;i<_33.length;i++){
var _36=String(_33[i]).toLowerCase();
if(_34==_36){
return _36;
}
}
}
return "";
};
this.getParentOfType=function(_37,_38){
while(_37){
if(_4.isTag(_37,_38).length){
return _37;
}
_37=_37.parentNode;
}
return null;
};
this.collapse=function(_39){
if(window.getSelection){
var _3a=_4.get_selection();
if(_3a.removeAllRanges){
if(_39){
_3a.collapseToStart();
}else{
_3a.collapseToEnd();
}
}else{
_3a.collapse(_39);
}
}else{
if(document.selection){
var _3b=_4.get_selection();
var _3c=_4.get_range(_3b);
_3c.collapse(_39);
_3c.select();
}
}
};
this.remove=function(){
var _s=null;
if(window.getSelection){
_s=_4.get_selection();
for(var i=0;i<_s.rangeCount;i++){
_s.getRangeAt(i).deleteContents();
}
return _s;
}else{
_s=_4.get_selection();
if(_s.type.toLowerCase()!="none"){
_s.clear();
}
return _s;
}
};
this.selectElementChildren=function(_3f){
if(window.getSelection){
var _40=_4.get_selection();
if(_40.setBaseAndExtent){
_40.setBaseAndExtent(_3f,0,_3f,_3f.innerText.length-1);
}else{
if(_40.removeAllRanges){
var _41=_4.create_range();
_41.selectNodeContents(_3f);
_40.removeAllRanges();
_40.addRange(_41);
}
}
}else{
if(document.selection&&document.body.createTextRange){
var _41=_3f.ownerDocument.body.createTextRange();
_41.moveToElementText(_3f);
_41.select();
}
}
};
this.selectElement=function(_42){
var _43=null;
if(_1.getSelection){
var _44=_4.get_selection();
if(_44.removeAllRanges){
_43=_4.create_range();
_43.selectNode(_42);
_44.removeAllRanges();
_44.addRange(_43);
}
}else{
if(document.selection&&document.body.createTextRange){
try{
_43=_4.create_range();
_43.addElement(_42);
_43.select();
}
catch(e){
_4.selectElementChildren(_42);
}
}
}
};
};
msos.selection.disableSelection=function(_45){
if(dojo.isMozilla){
_45.style.MozUserSelect="none";
}else{
if(dojo.isSafari){
_45.style.KhtmlUserSelect="none";
}else{
if(dojo.isIE){
_45.unselectable="on";
}else{
return false;
}
}
}
return true;
};
msos.selection.get_node_txt_length=function(_46){
var _47=0;
var _48=null;
if(_46&&_46.hasChildNodes()){
_48=_46.firstChild;
}
while(_48){
if(_48.nodeType==3){
_47+=_48.nodeValue.length;
}
_48=_48.nextSibling;
}
return _47;
};

